
package com.viweb.storemanager.temp;

import java.awt.Color;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JTable;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableCellRenderer;
import sun.swing.DefaultLookup;

public class TextCellRenderer extends DefaultTableCellRenderer {

    private Color oddLine = new Color(240, 240, 255);
    private Color evenLine = Color.WHITE;
    private Color selectedLine = new Color(172, 210, 255);
    private Color orderLine = new Color(236, 233, 216);
    boolean isOrderCell = false;

    /** Creates a new instance of TextCellRenderer */
    public TextCellRenderer() {
        super();
    }

    public TextCellRenderer(boolean isOrderCell) {
        super();
        this.isOrderCell = isOrderCell;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {

        if (!this.isOrderCell) {
            if (isSelected) {
                if (hasFocus) {
                    this.setBackground(this.selectedLine);
                } else {
                    this.setBackground(this.selectedLine);
                }
            } else {
                if (row % 2 == 0) {
                    this.setBackground(this.evenLine);
                } else {
                    this.setBackground(this.oddLine);
                }
            }

            if (hasFocus) {
                Border border = null;
                if (isSelected) {
                    border = DefaultLookup.getBorder(this, ui, "Table.focusSelectedCellHighlightBorder");
                }
                if (border == null) {
                    border = DefaultLookup.getBorder(this, ui, "Table.focusCellHighlightBorder");
                }
                this.setBorder(border);

                if (!isSelected && table.isCellEditable(row, column)) {
                    Color col;
                    col = DefaultLookup.getColor(this, ui, "Table.focusCellForeground");
                    if (col != null) {
                        super.setForeground(col);
                    }
                    col = DefaultLookup.getColor(this, ui, "Table.focusCellBackground");
                    if (col != null) {
                        super.setBackground(col);
                    }
                }
            } else {
                this.setBorder(noFocusBorder);
            }

            this.setForeground(Color.BLACK);
            // Create special border for cell order
        } else {
            if (hasFocus) {
                this.setForeground(new Color(255, 153, 0));
            } else {
                this.setForeground(Color.BLACK);
            }

            this.setBackground(this.orderLine);
            this.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,
                    this.orderLine,
                    this.orderLine,
                    null,
                    this.orderLine));
        }

        this.setEnabled(table.isEnabled());
        this.setFont(table.getFont());
        this.setText(" " + value.toString().trim() + " ");

        return this;
    }
}
